home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / write_ppm.pro < prev    next >
Text File  |  1997-07-08  |  2KB  |  83 lines

  1. ; $Id: write_ppm.pro,v 1.4 1997/04/05 00:29:08 kirk Exp $
  2. ;
  3. ; Copyright (c) 1994-1997. Research Systems, Inc. All rights reserved.
  4. ;    Unauthorized reproduction prohibited.
  5.  
  6. PRO WRITE_PPM, FILE, Image, ASCII = ascii
  7. ;+
  8. ; NAME:
  9. ;    WRITE_PPM
  10. ;
  11. ; PURPOSE:
  12. ;    Write an image to a PPM (true-color) or PGM (gray scale) file.
  13. ;    PPM/PGM format is supported by the PMBPLUS and Netpbm packages.
  14. ;
  15. ;    PBMPLUS is a toolkit for converting various image formats to and from
  16. ;    portable formats, and therefore to and from each other.
  17. ;
  18. ; CATEGORY:
  19. ;    Input/Output.
  20. ;    
  21. ; CALLING SEQUENCE:
  22. ;
  23. ;    WRITE_PPM, File, Image  ;Write a given array.
  24. ;
  25. ; INPUTS:
  26. ;    Image:    The 2D (gray scale) or 3D (true-color) array to be output.
  27. ;
  28. ; KEYWORD PARAMETERS:
  29. ;    ASCII = if set, formatted ASCII IO is used to write the image data.
  30. ;        If omitted, or set to zero, the far more efficient
  31. ;        binary IO (RAWBITS) format is used to write the image data.
  32. ;
  33. ; COMMON BLOCKS:
  34. ;    None.
  35. ;
  36. ; SIDE EFFECTS:
  37. ;    A file is written.
  38. ;
  39. ; RESTRICTIONS:
  40. ;    This routine only writes 8-bit deep PGM/PPM files of the standard
  41. ;    type.
  42. ;    Images should be ordered so that the first row is the top row.
  43. ;    If your image is not, use WRITE_PPM, File, REVERSE(Image, 2)
  44. ;
  45. ; MODIFICATION HISTORY:
  46. ;    Written Nov, 1994, DMS.
  47. ;-
  48. ; Copyright (c) 1994, Research Systems, Inc.  All rights reserved.
  49. ;    Unauthorized reproduction prohibited.
  50. ;
  51.  
  52. ; Check the arguments
  53. ON_IOERROR, bad_io
  54. ON_ERROR, 1
  55.  
  56. ; Is the image a 2-D array of bytes?
  57. img_size    = SIZE(image)
  58. maxval = max(image)
  59. if maxval gt 255 then message, $
  60.         'Data larger than 255 not allowed'
  61. IF img_size[0] eq 2 then begin
  62.     cols = img_size[1]
  63.     rows = img_size[2]
  64.     type = 5 - 3 * keyword_set(ascii)
  65. endif else if img_size[0] eq 3 then begin
  66.     if img_size[1] ne 3 then MESSAGE, 'True-color images must be (3,n,m)'
  67.     cols = img_size[2]
  68.     rows = img_size[3]
  69.     type = 6 - 3 * keyword_set(ascii)
  70. endif else message, 'IMAGE parameter must be dimensioned (n,m) or (3,n,m)'
  71.  
  72.  
  73. OPENW, unit, file, /GET_LUN, /BLOCK,/binary,/noautomode
  74. printf, unit, 'P'+strtrim(type,2)
  75. printf, unit, cols, rows, byte(maxval)
  76. if keyword_set(ascii) then printf, unit, byte(image) $
  77. else writeu, unit, byte(image)
  78. FREE_LUN, unit
  79. return
  80.  
  81. BAD_IO: Message, 'Error occured accessing PGM/PPM file:' + file
  82. end
  83.